const Url = {
  wechat: {
    login: '/third/wechat/login',
    bind: '/third/wechat/bind',
    unbind: '/third/wechat/unbind',
    oauthLogin: '/third/wechat/oauthLogin',
    sessionId: '/user-verify/js-code-login',
    // sessionId: '/third/wechat/getSessionId',
    userPhoneNumber: '/user-verify/get-phone',
    jssdk: '/weixin/weixin/jssdksign',
    subscribeTemplate: '/third/wechat/subscribeTemplate',
    miniProgramCode: '/third/wechat/wxacode',
  },
  apple: {
    login: '/third/apple/login',
  },
}

// 第三方登录
export const wechatLogin = (params) => uni.$uv.http.post(Url.wechat.login, params, { custom: { showLoading: true, loadingMsg: '登录中', toastIcon: 'success' } })
// 绑定微信
export const wechatBind = (params) => uni.$uv.http.post(Url.wechat.bind, params, { custom: { showLoading: true, loadingMsg: '绑定中', toastIcon: 'success' } })
// 解除绑定微信
export const wechatUnbind = (params) => uni.$uv.http.post(Url.wechat.unbind, params, { custom: { showLoading: true, loadingMsg: '绑定中', toastIcon: 'success' } })
// 公众号授权
export const wechatOauthLogin = (params) => uni.$uv.http.get(Url.wechat.oauthLogin, { params, custom: { showLoading: true, loadingMsg: '登录中', toastIcon: 'success' } })
// 获取小程序sessionKey（后端不会给前端返回真实的sessionKey）
export const getWechatSessionId = (params) => uni.$uv.http.post(Url.wechat.sessionId, params)
// 微信小程序 绑定一键获取的手机号
export const getWechatBindUserPhone = (params, config) =>
  uni.$uv.http.post(Url.wechat.userPhoneNumber, params, { ...config, custom: { showLoading: true, loadingMsg: '获取中', showMessage: true } })
// 网页jssdk
export const getWechatJssdk = (params) => uni.$uv.http.get(Url.wechat.jssdk, { params })
// 小程序订阅消息
export const getWechatSubscribeTemplate = (params = { platform: 'miniProgram' }) => uni.$uv.http.get(Url.wechat.subscribeTemplate, { params })
// 获取微信小程序码
export const getWechatMiniProgramCode = (path) =>
  uni.$uv.http.get(`${Url.wechat.miniProgramCode}?platform=miniProgram&payload=${encodeURIComponent(JSON.stringify({ path }))}`, { params })

// 苹果第三方登录
export const appleLogin = (params) => uni.$uv.http.post(Url.apple.login, params, { custom: { showLoading: true, loadingMsg: '登录中', toastIcon: 'success' } })
